Skip to content

Fix GH-22665: pdo_odbc OOB write on oversized diagnostic length#150

Closed
iliaal wants to merge 1 commit into
PHP-8.4from
fix/gh-22665-pdo-odbc-diag-oob
Closed

Fix GH-22665: pdo_odbc OOB write on oversized diagnostic length#150
iliaal wants to merge 1 commit into
PHP-8.4from
fix/gh-22665-pdo-odbc-diag-oob

Conversation

@iliaal

@iliaal iliaal commented Jul 10, 2026

Copy link
Copy Markdown
Owner

pdo_odbc_error() NUL-terminates the diagnostic buffer at the length SQLGetDiagRec reports, which on a truncated message is the full untruncated length and can reach or exceed the 512-byte last_err_msg buffer, writing the terminator out of bounds into the adjacent last_error field. Clamps the index to sizeof-1; the size_t cast also covers a negative driver-reported length. Reproduces with the SQLite3 ODBC driver (reports 512) via a failing query whose long identifier lengthens the message; the test skips without that driver.

pdo_odbc_error() writes the NUL terminator at
einfo->last_err_msg[errmsgsize], where errmsgsize is the diagnostic length
SQLGetDiagRec reports. On a truncated message (SQL_SUCCESS_WITH_INFO) the
driver reports the full untruncated length, which can reach or exceed the
512-byte buffer, so the terminator lands out of bounds in the adjacent
last_error field. Clamp the index to sizeof(last_err_msg) - 1; the size_t
cast also folds a negative driver-reported length into the same guard.

Fixes phpGH-22665
@iliaal

iliaal commented Jul 10, 2026

Copy link
Copy Markdown
Owner Author

Submitted upstream as php#22675.

@iliaal iliaal closed this Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant